<?php require 'head.php' ?>
<?php
$display_info = false;
if (isset($_POST['save'])) {

  $kw_index_config['header_weibo_xl'] = $_POST['header_weibo_xl'];
  $kw_index_config['header_weibo_tx'] = $_POST['header_weibo_tx'];
  $kw_index_config['contact_tel'] = $_POST['contact_tel'];
  $kw_index_config['contact_name'] = $_POST['contact_name'];
  $kw_index_config['contact_qq'] = $_POST['contact_qq'];
  $kw_index_config['contact_email'] = $_POST['contact_email'];
  $kw_index_config['introduction'] = get_magic_quotes_gpc() ? stripslashes(trim($_POST['introduction'])) : trim($_POST['introduction']);

  $code = "<?php\n\$kw_index_config = ".var_export($kw_index_config, true)."\n?>";
  file_put_contents(KW_DATA.'index_config.php', $code);

  $display_info = true;
}
$header_weibo_xl = $kw_index_config['header_weibo_xl'];
$header_weibo_tx = $kw_index_config['header_weibo_tx'];
$contact_tel = $kw_index_config['contact_tel'];
$contact_name = $kw_index_config['contact_name'];
$contact_qq = $kw_index_config['contact_qq'];
$contact_email = $kw_index_config['contact_email'];
$introduction = isset($kw_index_config['introduction']) ? $kw_index_config['introduction'] : '';
?>
  <div class="updated" style="<?php if (!$display_info) { ?>display: none;<?php } ?>">首页设置保存成功！</div>
  <div class="admin_page_name">首页设置</div>

<script language="javascript" src="xheditor/jquery.js"></script>
<script language="javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript">
function selectPic(no,currentThis){
    $("#pic_no").val('');
    $(currentThis).siblings('li').removeClass('selected-red');
    $(currentThis).toggleClass('selected-red');
    if($(currentThis).hasClass("selected-red")){
        $("#pic_no").val(no);
    }
}
function submitPic(){
    if(!$("#pic_no").val()){
        alert("请选择要上传/替换的图片位置！");
        return;
    }
    $("#fileField").click();
}
function deletePic(){
    if(!$("#pic_no").val()){
        alert("请选择要删除的图片！");
        return;
    }
    var path = '../kw_users/upload/slide/'+ $("#pic_no").val() +'.jpg'
    var url = 'cmd.php?act=DelIndPic&topath=' + path;
    //location.href = url;
    $.ajax({
      type: 'GET',
      url: url,
      success: function(data){
          //alert('ok');
          $("#loading" + $("#pic_no").val()).attr('src', '../kw_users/upload/slide/' + $("#pic_no").val() + '.jpg');
          $('.updated').show();
          $('.updated').html('图片删除成功！');
      }
    });
}
function ajaxFileUpload(){
    //加载图标   
    $("#loading" + $("#pic_no").val()).ajaxStart(function(){
            //$(this).show();
            $("#loading" + $("#pic_no").val()).attr('src', 'image/loading.gif');
    }).ajaxComplete(function(){
            //$(this).hide();
            $("#loading" + $("#pic_no").val()).attr('src', '../kw_users/upload/slide/' + $("#pic_no").val() + '.jpg');
    });
     //上传文件
     $.ajaxFileUpload(
          {
           url:'upImage.php?topath=../kw_users/upload/slide/'+ $("#pic_no").val() +'.jpg',    //需要链接到服务器地址
           secureuri:false,
           fileElementId:'fileField',          //文件选择框的id属性
           dataType: 'json',                    //服务器返回的格式，可以是json
           success: function (data, status)            //相当于java中try语句块的用法
                {      
                    //alert(data.msg);
                    $('.updated').show();
                    $('.updated').html('图片替换成功！');
                },
           error: function (data, status, e)            //相当于java中catch语句块的用法
                {
                    //alert(data.msg);
                    $('.updated').show();
                    $('.updated').html('添加失败');
                }
          });
}
function submit_upload(){
    $("#image_submit").click();
}
</script>
<form name="upImage_form" id="upImage_form" action="upImage.php" method="post" enctype="multipart/form-data" style="display:none;">
    <input type="file" name="fileField" id="fileField" onchange="submit_upload();" />
    <input type="hidden" name="pic_no" id="pic_no" value="" />
    <input type="button" value="提交" id="image_submit" onclick="ajaxFileUpload();"/>
</form>
<fieldset>
<legend>首页轮翻图片</legend> 
<ul> 
<li class="index-pic" onclick="selectPic(1,this);">
<img id="loading1" src="../kw_users/upload/slide/1.jpg" alt="暂无图片" title="点击上传新图片" style="width:100%;height:100%;">
</li>
<li class="index-pic" onclick="selectPic(2,this);">
<img id="loading2" src="../kw_users/upload/slide/2.jpg" alt="暂无图片" title="点击上传新图片" style="width:100%;height:100%;">
</li> 
<li class="index-pic" onclick="selectPic(3,this);">
<img id="loading3" src="../kw_users/upload/slide/3.jpg" alt="暂无图片" title="点击上传新图片" style="width:100%;height:100%;">
</li> 
<li class="index-pic" onclick="selectPic(4,this);">
<img id="loading4" src="../kw_users/upload/slide/4.jpg" alt="暂无图片" title="点击上传新图片" style="width:100%;height:100%;">
</li> 
<li class="index-pic" onclick="selectPic(5,this);">
<img id="loading5" src="../kw_users/upload/slide/5.jpg" alt="暂无图片" title="点击上传新图片" style="width:100%;height:100%;">
</li>
</ul>
<div style="clear:both;width:100%;height:8px;"></div>
<div style="width:80%;margin:0 auto;text-align: center;">
    <input type="button" value="上传/替换选中图片" class="" onclick="submitPic();"/>
    <input type="button" value="删除选中图片" class="" onclick="deletePic();"/>
</div>
</fieldset>

<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">

  <div class="small_form small_form2">
    <div class="field">
      <div class="label">新浪微博</div>
      <input class="textbox" type="text" name="header_weibo_xl" value="<?php echo htmlspecialchars($header_weibo_xl); ?>" />
      <div class="info">只要输入网址后面自己独有的微博名称。</div>
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label">腾讯微博</div>
      <input class="textbox" type="text" name="header_weibo_tx" value="<?php echo htmlspecialchars($header_weibo_tx); ?>" />
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label">联系电话</div>
      <input class="textbox" type="text" name="contact_tel" value="<?php echo htmlspecialchars($contact_tel); ?>" />
      <div class="info">网站头部和首页栏目处均用了。</div>
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label">联系人名</div>
      <input class="textbox" type="text" name="contact_name" value="<?php echo htmlspecialchars($contact_name); ?>" />
      <div class="info"></div>
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label">联系QQ</div>
      <input class="textbox" type="text" name="contact_qq" value="<?php echo htmlspecialchars($contact_qq); ?>" />
      <div class="info"></div>
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label">联系Email</div>
      <input class="textbox" type="text" name="contact_email" value="<?php echo htmlspecialchars($contact_email); ?>" />
      <div class="info"></div>
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label">团队简介</div>
      <textarea rows="5" class="textbox" name="introduction"><?php echo htmlspecialchars($introduction); ?></textarea>
      <div class="info">首页栏目显示用</div>
    </div>
    <div class="clear"></div>
    <div class="field">
      <div class="label"></div>
      <div class="field_body"><input class="button" type="submit" name="save" value="保存设置" /></div>
      <div class="info"></div>
    </div>
    <div class="clear"></div>
  </div>
</form>
<?php require 'foot.php' ?>